<template>
  <view class="body" :style="{backgroundColor:bgcolor}" >
    <view class="header">
      <view class="back" @click="back()">
        <uni-icons type="left" size="20"></uni-icons>
      </view>
      <text>活动详情</text>
    </view>
    <view class="image" @click="preview()">
      <image :src="activityInfo.imageUrl" mode="widthFix"></image>
    </view>
    <view class="activity-title" :style="{border:'1rpx solid',borderImage:activityInfo.eventName == '编程马拉松'?'linear-gradient(to right,#aef41a,#11dc7a) 1':''}">
      {{activityInfo.eventName}}
    </view>
    <view class="activity-main" :style="{border:'1rpx solid',borderImage:activityInfo.eventName == '编程马拉松'?'linear-gradient(to right,#aef41a,#11dc7a) 1':''}">
      <view class="activity-content">
        {{activityInfo.description}}
      </view>
      <view class="participantCount">
        可报名人数：{{activityInfo.participantCount}}
      </view>
      <view class="participantCrowd">
        面向对象：{{activityInfo.participantCrowd}}
      </view>
    </view>
    <view class="activity-detail" :style="{border:'1rpx solid',borderImage:activityInfo.eventName == '编程马拉松'?'linear-gradient(to right,#aef41a,#11dc7a) 1':''}">
      <view class="startTime">
        开始时间：{{activityInfo.eventDate}}
      </view>
      <view class="endTime">
        结束时间：{{activityInfo.eventTime}}
      </view>
      <view class="location">
        活动地点：{{activityInfo.location}}
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        activityId: '',
        activityInfo: {},
        bgcolor: '',
      };
    },
    onLoad(options) {
      this.activityId = options.id
      this.getActivityInfo()
    },
    methods: {
      back() {
        uni.navigateBack()
      },
      judgeColor() {
        if (this.activityInfo.eventName == '校园科技节') {
          this.bgcolor = '#4338d4'
        }else if(this.activityInfo.eventName == '书法比赛'){
          this.bgcolor = '#e9e3cb'
        }else if(this.activityInfo.eventName == '校园歌手大赛'){
          this.bgcolor = '#4338d4'
        }else if(this.activityInfo.eventName == '编程马拉松'){
          this.bgcolor = '#000'
        }
      },
      async getActivityInfo() {
        const data = await uni.$http.get(`/users/campusEvents/detail/${this.activityId}`)
        this.activityInfo = data.data.data
        this.judgeColor()
      },
      preview() {
        uni.previewImage({
          current: 0,
          urls: [this.activityInfo.imageUrl]
        })
      },
    }
  }
</script>

<style lang="scss">
  page {
    background-color: #fff;
  }

  .body {
    width: 100%;
    height: 1660rpx;
  }

  .header {
    position: relative;
    width: 100%;
    height: 140rpx;
    text-align: center;
    font-size: 36rpx;
    font-weight: 700;
    line-height: 170rpx;
    background-color: #fff;

    .back {
      position: absolute;
      top: 4rpx;
      left: 23rpx;
      height: 50rpx;
    }
  }

  .image {
    width: 100%;
    height: 500rpx;
    overflow: hidden;

    image {
      width: 100%;
      height: 100%;
    }
  }

  .activity-title {
    width: 88%;
    height: 40rpx;
    margin: 0 auto;
    margin-top: 30rpx;
    border-radius: 20rpx;
    padding: 30rpx 20rpx;
    font-size: 36rpx;
    line-height: 40rpx;
    background-color: rgba(0,0,0,0.3);
    color: #fff;
  }

  .activity-main {
    display: flex;
    flex-direction: column;
    width: 88%;
    margin: 0 auto;
    margin-top: 30rpx;
    padding: 20rpx 20rpx;
    border-radius: 20rpx;
    background-color: rgba(0, 0, 0, 0.3);
    color: #fff;
    font-size: 30rpx;

    .participantCount,
    .participantCrowd {
      width: 100%;
      margin-top: 20rpx;
    }
  }

  .activity-detail {
    display: flex;
    flex-direction: column;
    width: 88%;
    margin: 0 auto;
    margin-top: 30rpx;
    padding: 20rpx 20rpx;
    border-radius: 20rpx;
    background-color: rgba(0, 0, 0, 0.3);
    color: #fff;
    font-size: 30rpx;

    .endTime,
    .location {
      width: 100%;
      margin-top: 20rpx;
    }
  }
</style>